//
//  MultiThemeManager.h
//  MultiTheme
//
//  Created by Charith Nidarsha on 6/30/14.
//  Copyright (c) 2014 Charith Nidarsha. All rights reserved.
//

#import "CNThemeConstants.h"

#define GetColorForKey(key) [CNMultiThemeManager colorForKey:(key)]
#define GetImageForKey(key) [CNMultiThemeManager imageForKey:(key)]

@protocol ThemeableDelegate <NSObject>

@required
/**
 @description should implement this methods and needs to set Images and colors for the required UI Components. On Theme change this method will be getting called again.
 */
- (void) applyTheme;

@end

@interface CNMultiThemeManager : NSObject

/**
 @description returns the singleton instance of the ThemeManager. If you are extending your own class from this you can override this.
 @return ThemeManager singeleton object
 */
+ (instancetype) sharedManager;

/**
 @description you can override this method for your new Theme types you are defining.
 @return name for the given theme
 */
- (NSString*) nameFromTheme:(Theme)theme;

/**
 @description you can override this method if you are adding the "Themes" folder in a different place. Default  path is ApplicationRootFolder/AppReources/Themes. SO default returns "AppResources/Themes".
 @return name for the relative folder path for the "Themes" folder
 */
- (NSString*) folderPathToThemesFolder;

#pragma mark - convenient class methods to access from outside
/**
 @description you can call this method in the application:didFinishLaunchingWithOptions:
 @param theme Theme needs to be loaded
 */
+ (void) initilaizeWithTheme:(Theme)theme;

/**
 @description can register for theme change event. You can call this method like viewDidLoad: Once you register delegate will be weakly referenced by the MultiThemeManager.
 @param delegate object conforming to protocol <ThemeableDelegate>. this can be anything like UIView or UIViewController etc.
 */
+ (void) registerForThemeChange:(id<ThemeableDelegate>)delegate;

/**
 @description can unregister for theme change event. You can call this method like dealloc ex:
 @param delegate object needs to be unregister
 */
+ (void) unregisterForThemeChange:(id<ThemeableDelegate>)delegate;

/**
 @description You can call this method and change the theme across the application. It will trigger the applyTheme method in all the id<ThemeableDelegate> objects
 @param delegate new theme needs to be loaded
 */
+ (void) changeTheme:(Theme)theme;

/**
 @description retuns the current loaded theme
 */
+ (Theme) getCurrentTheme;

/**
 @description retuns the current theme theme
 */
+ (NSString*) getThemeName:(Theme)theme;

/**
 @description retuns the UIColor for the given color key. Color key needs to be declared in the colors.plist
 @param strThemeKey colorkey to be passed. color key should exists in the corresponding colors.plist file
 @throws InvalidColorKeyException if the given color key is not found
 */
+ (UIColor*) colorForKey:(NSString*)strColorKey;

/**
 @description returns the UIImage for the given image key. image should exists in the corresponding Images foloder. Image key should be simillar to [UIIImage imageNamed:]. So it will pick the 2x image automatically from the images foloder. for iPhone specific images suffix image name with -iPhone in the images folder. For example iPhone specific BackgroundImage name should be like ViewBgImage-iPhone@2x. But remember still you need to passe [ThemeManager getImage:@"ViewBGImage"] from outside. so it will automatically pick the iphone specific image. else it will load the default ViewBgImage.
 
 @param strImageKey imagekey to be passed
 @throws InvalidImageKeyException if the given image key is not found
 */
+ (UIImage*) imageForKey:(NSString*)strImageKey;

/**
 @description sets the common button images. So it will apply the Normal, selected and disabled images to the button. Like wise you can have simillar methods for your other UIControls.
 */
+ (void) applyThemeForDefaultButton:(UIButton*)button;

/**
 @description saves the current theme. you can get the saved theme by [MultiThemeManager getSavedTheme]
 */
+ (void) saveCurrentTheme;

/**
 @description returns the saved theme. you can get the saved theme by [MultiThemeManager getSavedTheme]
 */
+ (Theme) getSavedTheme;

/**
 @description clears the internal data structures to release memory. this will clear the cached UIColor objects and UIImage objects from memory. You can call this method in UIViewController didReceiveMemoryWarning or UIApplicationDelegate
 */
+ (void) respondsToMemoryWarnings;
@end
